package zpy.servlet.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * Servlet implementation class RequestLineServlet
 */
@WebServlet("/RequestLineServlet")
public class RequestLineServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestLineServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String method = request.getMethod();
		String scheme = request.getScheme();
		String serverName = request.getServerName();
		int serverPort = request.getServerPort();
		String contetxtPath =request.getContextPath();
		String servletPath = request.getServletPath();
		String queryString = request.getQueryString();
		String protocol = request.getProtocol();
		String requestUri = request.getRequestURI();
		String requestUrl = request.getRequestURL().toString();
		request.setAttribute("method", method);
		request.setAttribute("scheme", scheme);
		request.setAttribute("serverName", serverName);
		request.setAttribute("serverPort", serverPort);
		request.setAttribute("contetxtPath", contetxtPath);
		request.setAttribute("servletPath", servletPath);
		request.setAttribute("queryString", queryString);
		request.setAttribute("protocol", protocol);
		request.setAttribute("requestUri", requestUri);
		request.setAttribute("requestUrl", requestUrl);
		getServletContext().getRequestDispatcher("/WEB-INF/jsp/threeChapt/requestline.jsp")
		.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
